package com.zgw.his.design.model.property.edit;

import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Dialog;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Table;
import org.eclipse.swt.widgets.TableColumn;
import org.eclipse.swt.custom.TableCursor;
import org.eclipse.swt.widgets.TableItem;
import org.eclipse.swt.custom.SashForm;
import org.eclipse.swt.custom.ScrolledComposite;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.widgets.Composite;

public class TestDialog extends Dialog {

	protected Object result;
	protected Shell shell;
	private Text text;
	private Composite composite;

	/**
	 * Create the dialog.
	 * 
	 * @param parent
	 * @param style
	 */
	public TestDialog(Shell parent, int style) {
		super(parent, style);
		setText("SWT Dialog");
	}

	public TestDialog(Shell parent, int style, Object result) {
		super(parent, style);
		setText("SWT Dialog");
		this.result = result;
	}

	/**
	 * Open the dialog.
	 * 
	 * @return the result
	 */
	public Object open() {
		createContents();
		shell.open();
		shell.layout();
		Display display = getParent().getDisplay();
		while (!shell.isDisposed()) {
			if (!display.readAndDispatch()) {
				display.sleep();
			}
		}
		return result;
	}

	public static void main(String[] args) {
		TestDialog d = new TestDialog(new Shell(), SWT.NONE);
		d.open();
	}

	/**
	 * Create contents of the dialog.
	 */
	private void createContents() {
		shell = new Shell(getParent(), SWT.DIALOG_TRIM | SWT.MAX
				| SWT.APPLICATION_MODAL);
		shell.setSize(580, 480);
		shell.setText("标识码设置");
		{
			text = new Text(shell, SWT.BORDER | SWT.MULTI);
			text.setBounds(10, 10, 293, 22);
		}
		if (this.result != null) {
			text.setText(result.toString());
		}
		Button bu = new Button(shell, SWT.NONE);
		bu.setText("确定");
		bu.setBounds(450, 400, 100, 22);
		bu.addSelectionListener(new SelectionAdapter() {
			@Override
			public void widgetSelected(SelectionEvent e) {
				doOk();
			}
		});
	}

	protected void doOk() {
		this.result = text.getText();
		
		shell.close();
	}
}
